#!/usr/bin/perl

package Login;
use strict;
use Data::Dumper;

sub new
{
    my $class = shift;

    my $self = {};
    $self->{EM_IDS} = {};
    $self->{RECORDS} = {};

    bless ($self, $class);

    return $self;
}

sub Insert
{
    my $self = shift;
    my $emid = shift;
    my $datetime = shift;

    $self->{EM_IDS}->{$emid} = 1;

    my $v_date = substr($datetime, 0, 8);
    $v_date = substr($v_date, 0, 4) . "-" . substr($v_date, 4, 2) . "-" . substr($v_date, 6);
    my $v_time = substr($datetime, 8);
    $v_time = substr($v_time, 0, 2) . ":" . substr($v_time, 2, 2);

    push @{$self->{RECORDS}->{$emid}->{$v_date}}, "$v_time";
}

sub GetAllIds
{
    my $self = shift;

    return sort keys %{$self->{EM_IDS}};
}

sub GetAllDates
{
    my $self = shift;
    my %dates = ();

    for my $id (keys %{$self->{EM_IDS}}) {
        for my $date (keys %{$self->{RECORDS}->{$id}}) {
            $dates{$date} = 1;
        }
    }

    return sort keys %dates;
}

sub GetTime
{
    my $self = shift;
    my $emid = shift;
    my $date = shift;

    return $self->{RECORDS}->{$emid}->{$date} ?
        "'" . join(" ", @{$self->{RECORDS}->{$emid}->{$date}}) . "'" : "";
}

1;
